﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using ImmlPad.UpdateManagement;

namespace ImmlPad.Test
{
    public class TaskingTests
    {
        [Fact]
        public void Update_Task_Detects_Newer_Versions_And_Notifies()
        {
            var newVersionAvailable = false;
            var updateTask = new CheckForUpdateTask(new Version());

            updateTask.NewVersionAvailable += delegate
            {
                newVersionAvailable = true;
            };
            
            updateTask.Update(float.MinValue);
            updateTask.WaitForCompletion();

            Assert.True(newVersionAvailable);
        }

        [Fact]
        public void Update_Task_Detects_Version_Is_Current_And_Does_Not_Notify()
        {
            var newVersionAvailable = false;
            var updateTask = new CheckForUpdateTask(new Version(int.MaxValue, int.MaxValue));

            updateTask.NewVersionAvailable += delegate
            {
                newVersionAvailable = true;
            };

            updateTask.Update(float.MinValue);
            updateTask.WaitForCompletion();

            Assert.False(newVersionAvailable);
        }
    }
}
